//
//  NetListController.m
//  FinancialProduct
//
//  Created by Stella on 2017/9/18.
//  Copyright © 2017年 maq. All rights reserved.
//

#import "myWebViewController.h"
#import "HandleNetProduct.h"
#import "TransactionInfoCell.h"
#import "ReportController.h"
#import "CKPuslichTool.h"
#import "SearchController.h"
#import "CKPuslichTool.h"
#import "UserModel.h"
#import "NetWorthController.h"
#import "NetListController.h"

@interface NetListController ()
@property (weak, nonatomic) IBOutlet UITableView *mTableView;
@property(strong, nonatomic)NSMutableArray *dataArray;
@property (weak, nonatomic) IBOutlet UIView *noDataView;
@property (weak, nonatomic) IBOutlet UIButton *searchBt;
@property(strong,nonatomic)NSString *searchNa;
@end

@implementation NetListController
- (void)viewDidLoad {
    [super viewDidLoad];
    [self.searchBt setTitle:@"搜索产品" forState:UIControlStateNormal];
    [self.searchBt setTitleColor:[UIColor lightGrayColor] forState:UIControlStateNormal];
    
    self.mTableView.estimatedRowHeight=50;
    self.mTableView.rowHeight = UITableViewAutomaticDimension;
    self.dataArray=[[NSMutableArray alloc] init];
    _searchNa=@"";
    [self getListData];

    // Do any additional setup after loading the view.
}
-(IBAction)rightButton:(UIButton *)barBt{
    [self.searchBt setTitle:@"搜索产品" forState:UIControlStateNormal];
    [self.searchBt setTitleColor:[UIColor lightGrayColor] forState:UIControlStateNormal];
    //去搜索页面
    SearchController *vc=(SearchController *)[CKPuslichTool getViewControllerFromStroyBoard:@"My" viewID:@"SearchController"];
    vc.whereFrom=@"Report";
    vc.returnSearchContent = ^(NSString *searchContent) {
        _searchNa=searchContent;
        [self.searchBt setTitle:searchContent forState:UIControlStateNormal];
        [self.searchBt setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [self getListData];
    };
    
    [self.navigationController pushViewController:vc animated:YES];
    
}

-(void)getListData{
    UserModel *model=[UserModel getUser];
    int mid=[model.CustomerID intValue];
    NSDictionary *params=@{@"AAAMethodName":@"InfodisclosureNet",
                           @"CustomerID":@(mid),@"SubProductName":_searchNa};
    if ([self.title isEqualToString:@"产品报告"]) {
        params=@{@"AAAMethodName":@"InfodisclosureReport",
                 @"CustomerID":@(mid)};
    }
    [HandleNetProduct getListforParams:params Success:^(NSArray *data) {
        [self.dataArray removeAllObjects];
        if (data.count>0) {
            
            [self.dataArray addObjectsFromArray:data];
            self.noDataView.hidden=YES;
        }else{
            self.noDataView.hidden=NO;
        }
        [self.mTableView reloadData];
    } Failure:^(NSString *errorInfo) {
        
    }];

    
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


#pragma mark - Table view data source
//- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
//{
//    return 50;
//    
//}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    
    return 1;
    
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    
    return self.dataArray.count;
    
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    TransactionInfoCell *cell=[tableView dequeueReusableCellWithIdentifier:@"TransactionInfoCell" forIndexPath:indexPath];
    cell.selectionStyle=UITableViewCellSelectionStyleNone;
    cell.accessoryType=UITableViewCellAccessoryNone;
   
    cell.nameLa.text=_dataArray[indexPath.row][@"SubProductName"];
 
    
    return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    
    return 0.01f;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 0.01;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    NetWorthController *vc=(NetWorthController *)[CKPuslichTool getViewControllerFromStroyBoard:@"My" viewID:@"NetWorthController"];
    vc.SubProductId=self.dataArray[indexPath.row][@"SubProductId"];
    vc.SubProductName=_dataArray[indexPath.row][@"SubProductName"];
    vc.productTypeLevel1=_dataArray[indexPath.row][@"ProductTypeLevel1"];
    [self.navigationController pushViewController:vc animated:YES];
}


@end
